//
// This file is part of cpp-lib, a library of C++ functions and classes.
// Cpp-lib is copyright (C) 2004 and onwards, The CPL Interest Group.
//
// This library is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation; either version 2.1 of the License, or (at
// your option) any later version.
//
// This library is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser
// General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this library (see the file COPYING); if not, write to the
// Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
// 02111-1307  USA
//
// $Id$
//


#ifndef CPP_LIB_FILE_SYS_H
#define CPP_LIB_FILE_SYS_H

#include <string>
#include <memory>


namespace cpl { namespace detail_ { struct file_impl ; } }


namespace cpl {

namespace util {

namespace file {


struct File {

  // Open the file.  Subsequent opens are possible during our lifetime.
  File( std::string const& name ) ;

  // Return last access time [s] (since some fixed epoch).
  double const modification_time() ;

  ~File() ;

private:

  File( File const& ) ;

  std::auto_ptr< cpl::detail_::file_impl > impl ;

} ;


//
// An object watching the modification status of a file.
//
// (Necessary because Windows doesn't correctly report modification
// times once file is opened.)
//

struct file_name_watcher {

  file_name_watcher( std::string const& name )
  : name( name ) , t( File( name ).modification_time() ) {}

  // True iff the file was written to since last modified() call.
  bool modified() ;

private:

  std::string const name ;
  double t ;

} ;


//
// An object watching the modification status of a file.
//

struct file_watcher {

  file_watcher( std::string const& name )
  : f( name ) , t( f.modification_time() ) {}

  // True iff the file was written to since last modified() call.
  bool modified() ;

private:

  File f ;
  double t ;

} ;


} // namespace file

} // namespace util

} // namespace cpl



#endif // CPP_LIB_FILE_SYS_H
